package com.sysu.homework.DAO.Impl;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.sysu.homework.DAO.CourseDAO;
import com.sysu.homework.model.Course;

@Component("courseDAO")
public class CourseDAOImpl implements CourseDAO {
	
	private HibernateTemplate hibernateTemplate;

	@Override
	public int save(Course course) {
		if(hibernateTemplate.save(course) != null)
			return 1;
		return -1;
	}

	@Override
	public Course getCourseById(int id) {
		Course course = (Course)hibernateTemplate.get(Course.class, id);
		return course;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

}
